﻿using System.Collections.Generic;
using System.Linq;
using eCommMongo.Core;
using eCommMongo.Core.Data;
using eCommMongo.Core.Domain.Customers;
using eCommMongo.Core.Domain.Posts;
using eCommMongo.Service.Posts;

namespace eCommMongo.Service.Statuses
{
    public class CommentService : ICommentService
    {

        private IMongoRepository<Comment> _commentRep;
        private IMongoRepository<Customer> _customerRep;
        private IMongoRepository<Post> _statusRep;


        public CommentService(IMongoRepository<Comment> commentRep, IMongoRepository<Customer> customerRep, IMongoRepository<Post> statusRep)
        {
            _commentRep = commentRep;
            _customerRep = customerRep;
            _statusRep = statusRep;
        }

        public IList<Comment> Show(int statusId)
        {
            throw new System.NotImplementedException();
        }

        public Comment GetComment(string commentId)
        {



            var query = from c in _commentRep.Table()
                        where c.Id == commentId select c;
            var p = query.SingleOrDefault();
            if (p != null)
            {
                return PostMapper.ToComment(p);
            }
            else
            {
                return null;
            }
                        
        }

        public IList<Comment> GetPagedComments(string statusId, int pageIndex, int pageSize)
        {
            var q = from c in _statusRep.Table()
                    where c.Id== statusId
                    select c;


            var comments = q.SingleOrDefault().Comments;

            var tempResult = new PagedList<Comment>(comments, pageIndex, pageSize);

            return PostMapper.ToComments(tempResult.ToList()).ToList();
        }

       
    }
}